/**
 * @filename:ExportModelConfigServiceImpl 2023-11-12 08:11:06
 * @project com/lwl/blue  V1.0
 * Copyright(c) 2018 <a href=mailto:lanwenliang@yidianlife.com>蓝文良</a> Co. Ltd. 
 * All right reserved. 
 */
package com.lwl.blue.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwl.blue.commont.base.BizException;
import com.lwl.blue.commont.base.ErrorCode;
import com.lwl.blue.commont.base.JsonResult;
import com.lwl.blue.commont.base.PageParam;
import com.lwl.blue.dao.ExportModelConfigDao;
import com.lwl.blue.entity.ExportModelConfig;
import com.lwl.blue.service.ExportModelConfigService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**   
 * <p>自定义serviceImpl写在这里</p>
 * 
 * <p>说明： 导出模板配置表服务实现层</P>
 * @version: V1.0
 * @author: <a href=mailto:lanwenliang@yidianlife.com>蓝文良</a>
 * 
 */
@Service
public class ExportModelConfigServiceImpl extends ServiceImpl<ExportModelConfigDao, ExportModelConfig> implements ExportModelConfigService {
    @Value("${upload.filePath}")
    private String filePath;
    @Value("${export.file.path.prefix}")
    private String prefix;

    @Resource
    private ExportModelConfigDao exportModelConfigDao;
    @Override
    public JsonResult<Page<ExportModelConfig>> pages(PageParam<ExportModelConfig> pageParam) {
        Page<ExportModelConfig> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        return new JsonResult<Page<ExportModelConfig>>().success(exportModelConfigDao.pages(page, pageParam.getParam()));

    }
    @Override
    public ExportModelConfig getFilePath(Integer id) {
        ExportModelConfig data = exportModelConfigDao.selectById(id);
        if(data.getUrl()==null){
            throw new BizException(ErrorCode.EXPORT_DEMO_IS_NOT_ERROR.getCode(), ErrorCode.EXPORT_DEMO_IS_NOT_ERROR.getMsg());
        }
        data.setUrl(data.getUrl().replaceFirst(prefix,filePath)); ;
        return data;
    }
}